/*    This file is part of nit.
 *
 *    Nit is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Nit is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with nit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TRIE_H
#define TRIE_H

#include "map.h"

typedef struct Trie_entry {
	Map map;
	struct Trie_entry *prev;
	void *dat;
} Trie_entry;

typedef struct Trie {
	Trie_entry *root;
	Disposer disposer;
} Trie;

Nit_error
trie_init(Trie *trie, Disposer *disposer, const void *root_dat);

void
trie_dispose(Trie *trie);

/* For single values */

Trie_entry *
trie_add(Trie *trie, Trie_entry *entry, uint32_t key_len,
	 const void *key, const void *val);

Nit_error
trie_remove(Trie *trie, Trie_entry *entry, uint32_t key_len,
	    const void *key, void **val);

Trie_entry *
trie_get(Trie_entry *entry, uint32_t key_len, const void *key);

/* For lists of keys */

Trie_entry *
trie_list_add(Trie *trie, Trie_entry *entry, List *key_list, const void *val);

Nit_error
trie_list_remove(Trie *trie, Trie_entry *entry, List *key_list, void **val);

Trie_entry *
trie_list_get(Trie_entry *entry, List *key_list);

#endif
